package com.google.code.basic.oop;

import java.util.List;

import org.apache.log4j.Logger;

public class AlarmCollectorServiceImpl implements AlarmCollectorService {

	private static final Logger logger = Logger.getLogger(AlarmCollectorServiceImpl.class);

	private String remoteFileName;
	private String remoteWorkingDirectory;
	private String LocalAlarmDirName;
	private FTPService ftpService;
	
	public AlarmCollectorServiceImpl(FTPService ftpService) {
		 this.ftpService = ftpService;
	}

	public String getRemoteWorkingDirectory() {
		return remoteWorkingDirectory;
	}


	public void setRemoteWorkingDirectory(String remoteWorkingDirectory) {
		this.remoteWorkingDirectory = remoteWorkingDirectory;
	}

	public String getLocalAlarmDirName() {
		return LocalAlarmDirName;
	}


	public void setLocalAlarmDirName(String localAlarmDirName) {
		LocalAlarmDirName = localAlarmDirName;
	}


	public String getRemoteFileName() {
		return remoteFileName;
	}

	public void setRemoteFileName(String regex) {
		this.remoteFileName = regex;
	}

	public boolean retrieveAlarmsFromConnector(NetworkElementConnector connector) {
		boolean result = false;
		if(connector == null) { return false; };
		ftpService.setRemoteWorkingDirectory(this.getRemoteWorkingDirectory());
		ftpService.setLocalWorkingDirectory(this.getLocalAlarmDirName());
		result = ftpService.downloadRemoteFiles(connector, this.getRemoteFileName());
		
		if(!result) {
			logger.debug(LoggerFormatter.format(1,LoggerFormatter.Level.DEBUG,	"Failed to fetch file(s): " 
						+ this.getRemoteFileName() + " from " + connector.getConnectionName()));
		}
		return result;
	}
	
	public boolean retrieveAlarmsFromAllConnectors(List<NetworkElementConnector> connectors) {
		boolean result = true;
		for (int i = 0; i < connectors.size(); i++) {
			if(retrieveAlarmsFromConnector(connectors.get(i)) == false) {result = false;}
		}
		return result;
	}
}


